package gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

import stuff.CloseAction;
import stuff.MinimizeAction;

import database.JDBC;

public class GUIMain extends CustomJPanel{
	
	public static final int GUIQUESTIONMANAGER_ID = 1;
	public static final String GUIQUESTIONMANAGER_STR = "QUẢN LÝ CÂU HỎI";
	
	private static final long serialVersionUID = 1L;
	protected JFrame parent;
	private static JDBC db;
	protected JPanel titlePanel, contentPanel;
	protected JLabel titlebar;
	protected JLabel title;
	protected JPanel topPanel;
	protected JPanel bottomPanel;
	protected JButton minButton;
	protected JButton exitButton;
	
	public GUIMain(JFrame param, int cornerIndex) {
		super(param, cornerIndex);
		this.parent = param;
		setPreferredSize(new Dimension(800, 600));
		setLayout(new BorderLayout());
		//Top panel handler
		titlePanel = new JPanel(new BorderLayout());
		titlePanel.setOpaque(false);
		titlebar = new JLabel("ThiGPLX Server");
		titlebar.setForeground(new Color(255, 255, 255, 200));
		titlePanel.setBorder(new EmptyBorder(0, 10, 0, 3));
		JPanel topRight = new JPanel(new FlowLayout(FlowLayout.RIGHT));
		minButton = new CustomJButton("", 20, 20, CustomJButton.BLUE, CustomJButton.LIGHTER, 
				Color.DARK_GRAY, 0, true, false);
		
		minButton.setAction(new MinimizeAction(this.parent));
		exitButton = new CustomJButton("", 20, 20, CustomJButton.RED, CustomJButton.LIGHTER, 
				Color.DARK_GRAY, 0, true, false);
		exitButton.setAction(new CloseAction());
		topRight.add(minButton);
		topRight.add(exitButton);
		topRight.setOpaque(false);
		titlePanel.add(titlebar,BorderLayout.CENTER);
		titlePanel.add(topRight,BorderLayout.EAST);
		
		contentPanel = new JPanel(new BorderLayout(20, 20));
		contentPanel.setOpaque(false);
		topPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
		topPanel.setOpaque(false);
		
		//topPanel
		title = new JLabel();
		title.setFont(getFont().deriveFont(60f));
		title.setHorizontalAlignment(SwingConstants.CENTER);
		title.setForeground(new Color(255, 255, 255, 200));
		title.setPreferredSize(new Dimension(this.getPreferredSize().width, this.getPreferredSize().height/6));
		topPanel.add(title);
		
		bottomPanel = new JPanel();
		contentPanel.add(topPanel, BorderLayout.NORTH);
		contentPanel.add(bottomPanel,BorderLayout.CENTER);
		
		add(titlePanel,BorderLayout.NORTH);
		add(contentPanel,BorderLayout.CENTER);
	}
	
	public JFrame getFrame(){
		return this.parent;
	}
	
	public void setTitle(String param){
		this.title.setText(param);
	}
	
	public String getTitle(){
		return this.title.getText();
	}

	public static JDBC getDb() {
		return db;
	}

	public static void setDb(JDBC db) {
		GUIMain.db = db;
	}
}
